from django.conf import settings
import django.db.models.deletion
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Department',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_comment='部门名称', max_length=255, verbose_name='部门名称')),
                ('manager', models.CharField(db_comment='部门经理', max_length=255, verbose_name='部门经理')),
                ('description', models.TextField(blank=True, db_comment='部门描述', null=True, verbose_name='部门描述')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
            ],
            options={
                'verbose_name': '部门',
                'verbose_name_plural': '部门',
                'db_table': 'mentorx_departments',
                'db_table_comment': '部门表',
            },
        ),
        migrations.CreateModel(
            name='FinanceCategory',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_comment='科目名称', max_length=100, verbose_name='科目名称')),
                ('type', models.CharField(choices=[('income', '收入'), ('expense', '支出')], db_comment='收支类型:income收入,expense支出', max_length=10, verbose_name='收支类型')),
                ('description', models.TextField(blank=True, db_comment='科目说明', null=True, verbose_name='科目说明')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('parent', models.ForeignKey(blank=True, db_comment='上级科目ID', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='company.financecategory', verbose_name='上级科目')),
            ],
            options={
                'verbose_name': '收支科目',
                'verbose_name_plural': '收支科目',
                'db_table': 'mentorx_finance_categories',
                'db_table_comment': '收支科目表',
            },
        ),
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('phone', models.CharField(db_comment='手机号', max_length=20, unique=True, verbose_name='手机号')),
                ('role', models.CharField(choices=[('admin', '管理员'), ('manager', '部门经理'), ('employee', '职员')], db_comment='用户角色', default='employee', max_length=10, verbose_name='角色')),
                ('hire_date', models.DateTimeField(db_comment='入职日期', verbose_name='入职日期')),
                ('department', models.ForeignKey(blank=True, db_comment='所属部门', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='users', to='company.department', verbose_name='所属部门')),
                ('user', models.OneToOneField(db_comment='关联用户', on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL, verbose_name='用户')),
            ],
            options={
                'verbose_name': '用户档案',
                'verbose_name_plural': '用户档案',
                'db_table': 'mentorx_user_profiles',
                'db_table_comment': '用户扩展信息表',
            },
        ),
        migrations.CreateModel(
            name='Company',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(db_comment='公司名称', max_length=200, verbose_name='公司名称')),
                ('legal_person', models.CharField(db_comment='法人代表', max_length=100, verbose_name='法人代表')),
                ('registration_number', models.CharField(db_comment='统一社会信用代码', max_length=100, unique=True, verbose_name='统一社会信用代码')),
                ('industry', models.CharField(choices=[('tech', '科技'), ('finance', '金融'), ('education', '教育'), ('healthcare', '医疗'), ('retail', '零售'), ('manufacturing', '制造业'), ('service', '服务业'), ('other', '其他')], db_comment='所属行业', max_length=50, verbose_name='所属行业')),
                ('registered_capital', models.DecimalField(db_comment='注册资本', decimal_places=2, max_digits=15, verbose_name='注册资本')),
                ('registration_date', models.DateField(db_comment='注册日期', verbose_name='注册日期')),
                ('address', models.CharField(db_comment='公司地址', max_length=500, verbose_name='公司地址')),
                ('contact_phone', models.CharField(db_comment='联系电话', max_length=50, verbose_name='联系电话')),
                ('contact_email', models.EmailField(db_comment='联系邮箱', max_length=254, verbose_name='联系邮箱')),
                ('description', models.TextField(blank=True, db_comment='公司简介', null=True, verbose_name='公司简介')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('updated_at', models.DateTimeField(db_comment='更新时间', auto_now=True, verbose_name='更新时间')),
            ],
            options={
                'verbose_name': '公司档案',
                'verbose_name_plural': '公司档案',
                'db_table': 'mentorx_companies',
                'db_table_comment': '公司档案表',
            },
        ),
        migrations.CreateModel(
            name='FinanceRecord',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('date', models.DateField(db_comment='交易日期', verbose_name='交易日期')),
                ('amount', models.DecimalField(db_comment='金额', decimal_places=2, max_digits=15, verbose_name='金额')),
                ('description', models.TextField(blank=True, db_comment='备注说明', null=True, verbose_name='备注说明')),
                ('source', models.CharField(choices=[('manual', '手动录入'), ('import', '导入')], db_comment='数据来源:manual手动录入,import导入', default='manual', max_length=10, verbose_name='数据来源')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('category', models.ForeignKey(db_comment='收支科目ID', on_delete=django.db.models.deletion.CASCADE, related_name='finance_records', to='company.financecategory', verbose_name='收支科目')),
                ('department', models.ForeignKey(db_comment='所属部门ID', on_delete=django.db.models.deletion.CASCADE, related_name='finance_records', to='company.department', verbose_name='所属部门')),
                ('user_profile', models.ForeignKey(db_comment='录入人ID', on_delete=django.db.models.deletion.CASCADE, related_name='finance_records', to='company.userprofile', verbose_name='录入人')),
            ],
            options={
                'verbose_name': '财务流水',
                'verbose_name_plural': '财务流水',
                'ordering': ['-date', '-created_at'],
                'db_table': 'mentorx_finance_records',
                'db_table_comment': '财务流水表',
            },
        ),
        migrations.CreateModel(
            name='FinancialReport',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('report_type', models.CharField(choices=[('profit', '利润表'), ('balance', '资产负债表'), ('cashflow', '现金流量表')], db_comment='报表类型:profit利润表,balance资产负债表,cashflow现金流量表', max_length=20, verbose_name='报表类型')),
                ('period', models.CharField(db_comment='报表周期', max_length=32, verbose_name='报表周期')),
                ('total_income', models.DecimalField(db_comment='总收入', decimal_places=2, default=0, max_digits=15, verbose_name='总收入')),
                ('total_expense', models.DecimalField(db_comment='总支出', decimal_places=2, default=0, max_digits=15, verbose_name='总支出')),
                ('net_profit', models.DecimalField(db_comment='净利润', decimal_places=2, default=0, max_digits=15, verbose_name='净利润')),
                ('generated_at', models.DateTimeField(db_comment='生成时间', default=django.utils.timezone.now, verbose_name='生成时间')),
                ('generated_by', models.ForeignKey(db_comment='生成者ID', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='financial_reports', to='company.userprofile', verbose_name='生成者')),
            ],
            options={
                'verbose_name': '财务报表',
                'verbose_name_plural': '财务报表',
                'db_table': 'mentorx_financial_reports',
                'db_table_comment': '财务报表表',
                'indexes': [models.Index(fields=['report_type', 'period'], name='finrep_type_period_idx')],
            },
        ),
        migrations.CreateModel(
            name='FinancialAnalysis',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key_insights', models.TextField(db_comment='关键洞察', verbose_name='关键洞察')),
                ('ai_suggestions', models.TextField(db_comment='AI建议', verbose_name='AI建议')),
                ('risk_level', models.CharField(choices=[('low', '低'), ('medium', '中'), ('high', '高')], db_comment='风险等级:low低,medium中,high高', default='low', max_length=10, verbose_name='风险等级')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('report', models.ForeignKey(db_comment='关联报表ID', on_delete=django.db.models.deletion.CASCADE, related_name='analyses', to='company.financialreport', verbose_name='关联报表')),
            ],
            options={
                'verbose_name': '财务分析',
                'verbose_name_plural': '财务分析',
                'ordering': ['-created_at'],
                'db_table': 'mentorx_financial_analysis',
                'db_table_comment': '财务分析表',
            },
        ),
        migrations.CreateModel(
            name='CompanyMember',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('role', models.CharField(choices=[('founder', '创始人'), ('partner', '合伙人'), ('employee', '员工'), ('advisor', '顾问')], db_comment='角色:founder创始人,partner合伙人,employee员工,advisor顾问', max_length=50, verbose_name='角色')),
                ('equity_ratio', models.FloatField(db_comment='股权比例百分比', default=0.0, verbose_name='股权比例(%)')),
                ('join_date', models.DateField(db_comment='加入日期', verbose_name='加入日期')),
                ('is_active', models.BooleanField(db_comment='是否在职', default=True, verbose_name='是否在职')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('company', models.ForeignKey(db_comment='所属公司ID', on_delete=django.db.models.deletion.CASCADE, related_name='members', to='company.company', verbose_name='所属公司')),
                ('user_profile', models.ForeignKey(db_comment='成员ID', on_delete=django.db.models.deletion.CASCADE, related_name='company_memberships', to='company.userprofile', verbose_name='成员')),
            ],
            options={
                'verbose_name': '公司成员',
                'verbose_name_plural': '公司成员',
                'db_table': 'mentorx_company_members',
                'db_table_comment': '公司成员表',
                'unique_together': {('company', 'user_profile')},
            },
        ),
        migrations.CreateModel(
            name='SmartFinancialReport',
            fields=[
                ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('report_type', models.CharField(choices=[('monthly', '月度报表'), ('quarterly', '季度报表'), ('annual', '年度报表')], db_comment='报表类型:monthly月度,quarterly季度,annual年度', max_length=20, verbose_name='报表类型')),
                ('period', models.CharField(db_comment='报表周期', max_length=50, verbose_name='报表周期')),
                ('revenue', models.DecimalField(db_comment='营收', decimal_places=2, default=0, max_digits=15, verbose_name='营收')),
                ('expenses', models.DecimalField(db_comment='支出', decimal_places=2, default=0, max_digits=15, verbose_name='支出')),
                ('profit', models.DecimalField(db_comment='利润', decimal_places=2, default=0, max_digits=15, verbose_name='利润')),
                ('report_data', models.JSONField(db_comment='报表数据JSON', default=dict, verbose_name='报表数据')),
                ('ai_insights', models.TextField(blank=True, db_comment='AI洞察', null=True, verbose_name='AI洞察')),
                ('created_at', models.DateTimeField(db_comment='创建时间', default=django.utils.timezone.now, verbose_name='创建时间')),
                ('company', models.ForeignKey(db_comment='所属公司ID', on_delete=django.db.models.deletion.CASCADE, related_name='smart_reports', to='company.company', verbose_name='所属公司')),
                ('generated_by', models.ForeignKey(db_comment='生成者ID', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='smart_financial_reports', to='company.userprofile', verbose_name='生成者')),
            ],
            options={
                'verbose_name': '智能财务报表',
                'verbose_name_plural': '智能财务报表',
                'ordering': ['-created_at'],
                'db_table': 'mentorx_smart_financial_reports',
                'db_table_comment': '智能财务报表表',
            },
        ),
    ]

